# _*_ coding: UTF-8 _*_
# @Time     : 2022/4/25 15:53
# @Author   : Li Jie
# @Site     : http://www.cdtest.cn/
# @File     : index_003_login.py
# @Software : PyCharm

import unittest  # 导入测试框架

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait  # 导入显式等待类
from selenium.webdriver.support import expected_conditions  # 导入等待条件
from selenium.webdriver.common.action_chains import ActionChains

from po.page.index_page import IndexPage  # 导入首页类
from po.common.read_write_file import read_csv  # 导入读取csv文件函数


class Index004(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Chrome()
        self.wait = WebDriverWait(self.driver, 30)

        # 生成首页类对象
        self.index_page = IndexPage(self.driver, self.wait)

        # 读取用户账号数据
        self.data = read_csv('../data/users.csv')

    def test(self):
        for users in self.data:
            self.driver.get("https://www.baidu.com/")
            self.driver.maximize_window()

            self.index_page.click_top_login_button()
            self.index_page.input_user(users[0])
            self.index_page.input_pwd(users[1])
            self.index_page.click_login()
            # time.sleep(5)

    def tearDown(self) -> None:
        self.driver.quit()
